﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _004_指定目录文件修改后缀
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"E:\diskcache";
            DirectoryInfo root = new DirectoryInfo(path);
            FileInfo[] files = root.GetFiles();
            foreach (FileInfo file in files)
            {
                List<string> list = file.FullName.Split('.').ToList();
                if (list.Count > 1)
                {
                    list[list.Count - 1] = "jpg";
                }
                else
                {
                    list.Add("jpg");
                }
                string newPath = string.Join(".", list);
                file.MoveTo(newPath);
            }

        }
    }
}
